package com.getpebble.android.notifications.util;

import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Context;
import android.content.Intent;
import android.view.accessibility.AccessibilityManager;
import com.getpebble.android.common.core.trace.Trace;

public class AccessibilityServiceUtil {
    private static final String TAG = AccessibilityServiceUtil.class.getSimpleName();

    static boolean isPebbleAccessibilityEnabled(Context context) {
        AccessibilityManager am = (AccessibilityManager) context.getSystemService("accessibility");
        Trace.debug(TAG, "isPebbleAccessibilityEnabled()");
        for (AccessibilityServiceInfo service : am.getEnabledAccessibilityServiceList(-1)) {
            Trace.debug(TAG, "running accessibility service: " + service.getId());
            if ("com.getpebble.android/.notifications.PblAccessibilityService".equals(service.getId())) {
                return true;
            }
        }
        return false;
    }

    static void enableAccessibilityService(Context context) {
        if (context == null) {
            Trace.warning(TAG, "enableAccessibilityService: context is null");
        } else {
            context.startActivity(new Intent("android.settings.ACCESSIBILITY_SETTINGS"));
        }
    }
}
